﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Xpus.Website.Data
{
	/// <summary>
	/// 用于对数据字段进行检测的辅助类。
	/// </summary>
	public static class FieldChecker
	{
		/// <summary>
		/// 检查字段不能为空。
		/// </summary>
		/// <param name="fieldName">字段名字。</param>
		/// <param name="value">值。</param>
		public static void CheckFieldNotNull(string fieldName, object value)
		{
			if(value == null)
				ExceptionHelper.ThrowFieldNullException(fieldName);
		}

		/// <summary>
		/// 检查字符串字段不能过长。
		/// </summary>
		/// <param name="fieldName">字段名字。</param>
		/// <param name="value">值。</param>
		/// <param name="maxLength">最大长度。</param>
		public static void CheckFieldTooLong(string fieldName, string value, int maxLength)
		{
			if(value.Length > maxLength)
				ExceptionHelper.ThrowFieldTooLongException(fieldName, maxLength);
		}
	}
}
